<template>
  <div>
    <van-search @click="$router.push('/popup')" shape="round" background="#fc4a1a" placeholder="请输入搜索关键词" />
    <div class="category">
      <van-sidebar v-model="activeKey">
        <van-sidebar-item v-for="(item,index) in categoryList" :key="index" :title="item.name"
          @click="change(item.id)" />
      </van-sidebar>
      <div class="card-list">
        <div v-if="categoryGoodsList.length>0">
          <div class="card" v-for="(item,index) in categoryGoodsList" :key="index"
            @click="$router.push('/productDetail?productId=' + item.id)">
            <img :src="$baseUrl + item.pic" alt="">
            <p>{{item.goodsName}}</p>
          </div>
        </div>

        <div class="none" v-else>
          <h3 style="text-align:center;color:#f18162;">暂时没有相关商品哦~</h3>
          <img src="../assets/img/empy/暂无记录.png" alt="" style="width:100%;height:300px;" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getCategoryList, getCategoryGoodsList } from '@/request/api.js'
export default {
  data() {
    return ({
      keyword: '',
      categoryList: [],
      activeKey: 0,
      categoryGoodsList: []
    })
  },
  mounted() {
    getCategoryList().then(res => {
      this.categoryList = res.data

      this.$store.state.typeArr = res.data
    })
    this.change(1)
  },
  methods: {
    change(id) {
      getCategoryGoodsList({ id }).then(res => {
        this.categoryGoodsList = res.data
      })
    }
  }
}
</script>

<style scoped>
::v-deep .van-sidebar-item--select::before {
  background: #f18162;
}

.card-list {
  /* display: flex;
    flex-wrap: wrap;
    align-items: flex-start; */
  padding-top: 20px;
  background: #fff;
  width: calc(100% - 85px);
  overflow-y: scroll;
}

.card {
  float: left;
  width: 45%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 5px 5px 5px;
  height: 120px;
  background: #fff;
}

.category {
  background: #f18162;
  display: flex;
  justify-content: space-between;
  height: calc(100vh - 100px);
}

img {
  width: 60px;
  height: 60px;
  /* border-radius: 50%; */
}
</style>
